package com.pattern.once.proxy.d;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class P3 <T> implements InvocationHandler {

    private T tager;

    public P3(T tager) {
        this.tager = tager;
    }

    public <T> T newInstance (Class<T> tClass) {
        T n = (T) Proxy.newProxyInstance(tClass.getClassLoader(),new Class[]{tClass},this);
        return n;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("方法执行前");

        Object invoke = method.invoke(tager, args);
        System.out.println("方法执行后");

        return null;
    }
}
